<html>
<head>
  <title>../ex14.c</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<a href="../ex14.c">download the original source code</a>.
<pre>
<a name="line1">  1</a> <font color="#444444">/*
<a name="line2">  2</a>    Example 14
<a name="line3">  3</a> 
<a name="line4">  4</a>    Interface:      Semi-Structured interface (SStruct)
<a name="line5">  5</a> 
<a name="line6">  6</a>    Compile with:   make ex14
<a name="line7">  7</a> 
<a name="line8">  8</a>    Sample run:     mpirun -np 6 ex14 -n 10
<a name="line9">  9</a> 
<a name="line10"> 10</a>    To see options: ex14 -help
<a name="line11"> 11</a> 
<a name="line12"> 12</a>    Description:    This code solves the 2D Laplace equation using bilinear
<a name="line13"> 13</a>                    finite element discretization on a mesh with an &quot;enhanced
<a name="line14"> 14</a>                    connectivity&quot; point.  Specifically, we solve -Delta u = 1
<a name="line15"> 15</a>                    with zero boundary conditions on a star-shaped domain
<a name="line16"> 16</a>                    consisting of identical rhombic parts each meshed with a
<a name="line17"> 17</a>                    uniform n x n grid.  Every part is assigned to a different
<a name="line18"> 18</a>                    processor and all parts meet at the origin, equally
<a name="line19"> 19</a>                    subdividing the 2*pi angle there. The case of six processors
<a name="line20"> 20</a>                    (parts) looks as follows:
<a name="line21"> 21</a> 
<a name="line22"> 22</a>                                                 +
<a name="line23"> 23</a>                                                / \
<a name="line24"> 24</a>                                               /   \
<a name="line25"> 25</a>                                              /     \
<a name="line26"> 26</a>                                    +--------+   1   +---------+
<a name="line27"> 27</a>                                     \        \     /         /
<a name="line28"> 28</a>                                      \    2   \   /    0    /
<a name="line29"> 29</a>                                       \        \ /         /
<a name="line30"> 30</a>                                        +--------+---------+
<a name="line31"> 31</a>                                       /        / \         \
<a name="line32"> 32</a>                                      /    3   /   \    5    \
<a name="line33"> 33</a>                                     /        /     \         \
<a name="line34"> 34</a>                                    +--------+   4   +---------+
<a name="line35"> 35</a>                                              \     /
<a name="line36"> 36</a>                                               \   /
<a name="line37"> 37</a>                                                \ /
<a name="line38"> 38</a>                                                 +
<a name="line39"> 39</a> 
<a name="line40"> 40</a>                    Note that in this problem we use nodal variables, which are
<a name="line41"> 41</a>                    shared between the different parts.  The node at the origin,
<a name="line42"> 42</a>                    for example, belongs to all parts as illustrated below:
<a name="line43"> 43</a> 
<a name="line44"> 44</a>                                                 .
<a name="line45"> 45</a>                                                / \
<a name="line46"> 46</a>                                               .   .
<a name="line47"> 47</a>                                              / \ / \
<a name="line48"> 48</a>                                             o   .   *
<a name="line49"> 49</a>                                   .---.---o  \ / \ /  *---.---.
<a name="line50"> 50</a>                                    \   \   \  o   *  /   /   /
<a name="line51"> 51</a>                                     .---.---o  \ /  *---.---.
<a name="line52"> 52</a>                                      \   \   \  x  /   /   /
<a name="line53"> 53</a>                                       @---@---x   x---z---z
<a name="line54"> 54</a>                                       @---@---x   x---z---z
<a name="line55"> 55</a>                                      /   /   /  x  \   \   \
<a name="line56"> 56</a>                                     .---.---a  / \  #---.---.
<a name="line57"> 57</a>                                    /   /   /  a   #  \   \   \
<a name="line58"> 58</a>                                   .---.---a  / \ / \  #---.---.
<a name="line59"> 59</a>                                             a   .   #
<a name="line60"> 60</a>                                              \ / \ /
<a name="line61"> 61</a>                                               .   .
<a name="line62"> 62</a>                                                \ /
<a name="line63"> 63</a>                                                 .
<a name="line64"> 64</a> 
<a name="line65"> 65</a>                    This example is a identical to Example 13, except that it
<a name="line66"> 66</a>                    uses the SStruct FEM input functions instead of stencils to
<a name="line67"> 67</a>                    describe the problem.  This is the recommended way to set up a
<a name="line68"> 68</a>                    finite element problem in the SStruct interface.
<a name="line69"> 69</a> */</font>
<a name="line70"> 70</a> 
<a name="line71"> 71</a> <font color="0000ff"><strong>#include <font color="#008000">&lt;math.h&gt;</font></strong></font>
<a name="line72"> 72</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;_hypre_utilities.h&quot;</font></strong></font>
<a name="line73"> 73</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE_sstruct_mv.h&quot;</font></strong></font>
<a name="line74"> 74</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE_sstruct_ls.h&quot;</font></strong></font>
<a name="line75"> 75</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE.h&quot;</font></strong></font>
<a name="line76"> 76</a> 
<a name="line77"> 77</a> <font color="0000ff"><strong>#ifndef M_PI</strong></font>
<a name="line78"> 78</a> <font color="0000ff"><strong>#define M_PI 3.14159265358979</strong></font>
<a name="line79"> 79</a> <font color="0000ff"><strong>#endif</strong></font>
<a name="line80"> 80</a> 
<a name="line81"> 81</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;vis.c&quot;</font></strong></font>
<a name="line82"> 82</a> 
<a name="line83"> 83</a> <font color="#444444">/*
<a name="line84"> 84</a>    This routine computes the bilinear finite element stiffness matrix and
<a name="line85"> 85</a>    load vector on a rhombus with angle gamma. Specifically, let R be the
<a name="line86"> 86</a>    rhombus
<a name="line87"> 87</a>                               [3]------[2]
<a name="line88"> 88</a>                               /        /
<a name="line89"> 89</a>                              /        /
<a name="line90"> 90</a>                            [0]------[1]
<a name="line91"> 91</a> 
<a name="line92"> 92</a>    with sides of length h. The finite element stiffness matrix
<a name="line93"> 93</a> 
<a name="line94"> 94</a>                   S_ij = (grad phi_i,grad phi_j)_R
<a name="line95"> 95</a> 
<a name="line96"> 96</a>    with bilinear finite element functions {phi_i} has the form
<a name="line97"> 97</a> 
<a name="line98"> 98</a>                        /  4-k    -1  -2+k    -1 \
<a name="line99"> 99</a>                alpha . |   -1   4+k    -1  -2-k |
<a name="line100">100</a>                        | -2+k    -1   4-k    -1 |
<a name="line101">101</a>                        \   -1  -2-k    -1   4+k /
<a name="line102">102</a> 
<a name="line103">103</a>    where alpha = 1/(6*sin(gamma)) and k = 3*cos(gamma). The load vector
<a name="line104">104</a>    corresponding to a right-hand side of 1 is
<a name="line105">105</a> 
<a name="line106">106</a>                   F_j = (1,phi_j)_R = h^2/4 * sin(gamma)
<a name="line107">107</a> */</font>
<a name="line108">108</a> <strong>void</strong> <font color="#2040a0">ComputeFEMRhombus</font> <font color="4444FF">(</font><strong>double</strong> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font>, <strong>double</strong> <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font>, <strong>double</strong> <font color="#2040a0">gamma</font>, <strong>double</strong> <font color="#2040a0">h</font><font color="4444FF">)</font>
<a name="line109">109</a> <font color="4444FF"><strong>{</strong></font>
<a name="line110">110</a>    <strong>int</strong> <font color="#2040a0">i</font>, <font color="#2040a0">j</font><font color="4444FF">;</font>
<a name="line111">111</a> 
<a name="line112">112</a>    <strong>double</strong> <font color="#2040a0">h2_4</font> <font color="4444FF">=</font> <font color="#2040a0">h</font><font color="4444FF">*</font><font color="#2040a0">h</font>/<font color="#FF0000">4</font><font color="4444FF">;</font>
<a name="line113">113</a>    <strong>double</strong> <font color="#2040a0">sing</font> <font color="4444FF">=</font> <font color="#2040a0">sin</font><font color="4444FF">(</font><font color="#2040a0">gamma</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line114">114</a>    <strong>double</strong> <font color="#2040a0">alpha</font> <font color="4444FF">=</font> <font color="#FF0000">1</font>/<font color="4444FF">(</font><font color="#FF0000">6</font><font color="4444FF">*</font><font color="#2040a0">sing</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line115">115</a>    <strong>double</strong> <font color="#2040a0">k</font> <font color="4444FF">=</font> <font color="#FF0000">3</font><font color="4444FF">*</font><font color="#2040a0">cos</font><font color="4444FF">(</font><font color="#2040a0">gamma</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line116">116</a> 
<a name="line117">117</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">4</font><font color="4444FF">-</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line118">118</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line119">119</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">2</font><font color="4444FF">+</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line120">120</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line121">121</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">4</font><font color="4444FF">+</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line122">122</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line123">123</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">2</font><font color="4444FF">-</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line124">124</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">4</font><font color="4444FF">-</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line125">125</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line126">126</a>    <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">alpha</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">4</font><font color="4444FF">+</font><font color="#2040a0">k</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line127">127</a> 
<a name="line128">128</a>    <font color="#444444">/* The stiffness matrix is symmetric */</font>
<a name="line129">129</a>    <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font> <font color="#FF0000">4</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line130">130</a>       <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">j</font> <font color="4444FF">&lt;</font> <font color="#2040a0">i</font><font color="4444FF">;</font> <font color="#2040a0">j</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line131">131</a>          <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line132">132</a> 
<a name="line133">133</a>    <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font> <font color="#FF0000">4</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line134">134</a>       <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">h2_4</font><font color="4444FF">*</font><font color="#2040a0">sing</font><font color="4444FF">;</font>
<a name="line135">135</a> <font color="4444FF"><strong>}</strong></font>
<a name="line136">136</a> 
<a name="line137">137</a> 
<a name="line138">138</a> <strong>int</strong> <font color="#2040a0">main</font> <font color="4444FF">(</font><strong>int</strong> <font color="#2040a0">argc</font>, <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="4444FF">]</font><font color="4444FF">)</font>
<a name="line139">139</a> <font color="4444FF"><strong>{</strong></font>
<a name="line140">140</a>    <strong>int</strong> <font color="#2040a0">myid</font>, <font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line141">141</a>    <strong>int</strong> <font color="#2040a0">n</font><font color="4444FF">;</font>
<a name="line142">142</a>    <strong>double</strong> <font color="#2040a0">gamma</font>, <font color="#2040a0">h</font><font color="4444FF">;</font>
<a name="line143">143</a>    <strong>int</strong> <font color="#2040a0">vis</font><font color="4444FF">;</font>
<a name="line144">144</a> 
<a name="line145">145</a>    <font color="#2040a0">HYPRE_SStructGrid</font>     <font color="#2040a0">grid</font><font color="4444FF">;</font>
<a name="line146">146</a>    <font color="#2040a0">HYPRE_SStructGraph</font>    <font color="#2040a0">graph</font><font color="4444FF">;</font>
<a name="line147">147</a>    <font color="#2040a0">HYPRE_SStructMatrix</font>   <font color="#2040a0">A</font><font color="4444FF">;</font>
<a name="line148">148</a>    <font color="#2040a0">HYPRE_SStructVector</font>   <font color="#2040a0">b</font><font color="4444FF">;</font>
<a name="line149">149</a>    <font color="#2040a0">HYPRE_SStructVector</font>   <font color="#2040a0">x</font><font color="4444FF">;</font>
<a name="line150">150</a> 
<a name="line151">151</a>    <font color="#2040a0">HYPRE_Solver</font>          <font color="#2040a0">solver</font><font color="4444FF">;</font>
<a name="line152">152</a> 
<a name="line153">153</a>    <font color="#444444">/* Initialize MPI */</font>
<a name="line154">154</a>    <font color="#2040a0">MPI_Init</font><font color="4444FF">(</font><font color="4444FF">&amp;</font><font color="#2040a0">argc</font>, <font color="4444FF">&amp;</font><font color="#2040a0">argv</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line155">155</a>    <font color="#2040a0">MPI_Comm_rank</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="4444FF">&amp;</font><font color="#2040a0">myid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line156">156</a>    <font color="#2040a0">MPI_Comm_size</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="4444FF">&amp;</font><font color="#2040a0">num_procs</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line157">157</a> 
<a name="line158">158</a>    <font color="#444444">/* Set default parameters */</font>
<a name="line159">159</a>    <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#FF0000">10</font><font color="4444FF">;</font>
<a name="line160">160</a>    <font color="#2040a0">vis</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line161">161</a> 
<a name="line162">162</a>    <font color="#444444">/* Parse command line */</font>
<a name="line163">163</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line164">164</a>       <strong>int</strong> <font color="#2040a0">arg_index</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line165">165</a>       <strong>int</strong> <font color="#2040a0">print_usage</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line166">166</a> 
<a name="line167">167</a>       <strong>while</strong> <font color="4444FF">(</font><font color="#2040a0">arg_index</font> <font color="4444FF">&lt;</font> <font color="#2040a0">argc</font><font color="4444FF">)</font>
<a name="line168">168</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line169">169</a>          <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-n&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line170">170</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line171">171</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line172">172</a>             <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#2040a0">atoi</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line173">173</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line174">174</a>          <strong>else</strong> <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-vis&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line175">175</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line176">176</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line177">177</a>             <font color="#2040a0">vis</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line178">178</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line179">179</a>          <strong>else</strong> <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-help&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line180">180</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line181">181</a>             <font color="#2040a0">print_usage</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line182">182</a>             <strong>break</strong><font color="4444FF">;</font>
<a name="line183">183</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line184">184</a>          <strong>else</strong>
<a name="line185">185</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line186">186</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line187">187</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line188">188</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line189">189</a> 
<a name="line190">190</a>       <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">print_usage</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="4444FF">&amp;</font> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">)</font>
<a name="line191">191</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line192">192</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line193">193</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Usage: %s [&lt;options&gt;]<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line194">194</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line195">195</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;  -n &lt;n&gt;              : problem size per processor (default: 10)<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line196">196</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;  -vis                : save the solution for GLVis visualization<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line197">197</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line198">198</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line199">199</a> 
<a name="line200">200</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">print_usage</font><font color="4444FF">)</font>
<a name="line201">201</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line202">202</a>          <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line203">203</a>          <strong>return</strong> <font color="4444FF">(</font><font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line204">204</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line205">205</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line206">206</a> 
<a name="line207">207</a>    <font color="#444444">/* Set the rhombus angle, gamma, and the mesh size, h, depending on the
<a name="line208">208</a>       number of processors np and the given n */</font>
<a name="line209">209</a>    <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">num_procs</font> <font color="4444FF">&lt;</font> <font color="#FF0000">3</font><font color="4444FF">)</font>
<a name="line210">210</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line211">211</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font><font color="#FF0000">0</font><font color="4444FF">)</font> <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Must run with at least 3 processors!<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line212">212</a>       <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line213">213</a>       <font color="#2040a0">exit</font><font color="4444FF">(</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line214">214</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line215">215</a>    <font color="#2040a0">gamma</font> <font color="4444FF">=</font> <font color="#FF0000">2</font><font color="4444FF">*</font><font color="#2040a0">M_PI</font>/<font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line216">216</a>    <font color="#2040a0">h</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font>/<font color="#2040a0">n</font><font color="4444FF">;</font>
<a name="line217">217</a> 
<a name="line218">218</a>    <font color="#444444">/* 1. Set up the grid.  We will set up the grid so that processor X owns
<a name="line219">219</a>          part X.  Note that each part has its own index space numbering. Later
<a name="line220">220</a>          we relate the parts to each other. */</font>
<a name="line221">221</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line222">222</a>       <strong>int</strong> <font color="#2040a0">ndim</font> <font color="4444FF">=</font> <font color="#FF0000">2</font><font color="4444FF">;</font>
<a name="line223">223</a>       <strong>int</strong> <font color="#2040a0">nparts</font> <font color="4444FF">=</font> <font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line224">224</a> 
<a name="line225">225</a>       <font color="#444444">/* Create an empty 2D grid object */</font>
<a name="line226">226</a>       <font color="#2040a0">HYPRE_SStructGridCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">ndim</font>, <font color="#2040a0">nparts</font>, <font color="4444FF">&amp;</font><font color="#2040a0">grid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line227">227</a> 
<a name="line228">228</a>       <font color="#444444">/* Set the extents of the grid - each processor sets its grid boxes.  Each
<a name="line229">229</a>          part has its own relative index space numbering */</font>
<a name="line230">230</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line231">231</a>          <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line232">232</a>          <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font> <font color="#444444">/* lower-left cell touching the origin */</font>
<a name="line233">233</a>          <strong>int</strong> <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">n</font>,<font color="#2040a0">n</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font> <font color="#444444">/* upper-right cell */</font>
<a name="line234">234</a> 
<a name="line235">235</a>          <font color="#2040a0">HYPRE_SStructGridSetExtents</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line236">236</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line237">237</a> 
<a name="line238">238</a>       <font color="#444444">/* Set the variable type and number of variables on each part.  These need
<a name="line239">239</a>          to be set in each part which is neighboring or contains boxes owned by
<a name="line240">240</a>          the processor. */</font>
<a name="line241">241</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line242">242</a>          <strong>int</strong> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line243">243</a>          <strong>int</strong> <font color="#2040a0">nvars</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line244">244</a> 
<a name="line245">245</a>          <font color="#2040a0">HYPRE_SStructVariable</font> <font color="#2040a0">vartypes</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">HYPRE_SSTRUCT_VARIABLE_NODE</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line246">246</a>          <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font> <font color="#2040a0">nparts</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line247">247</a>             <font color="#2040a0">HYPRE_SStructGridSetVariables</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">i</font>, <font color="#2040a0">nvars</font>, <font color="#2040a0">vartypes</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line248">248</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line249">249</a> 
<a name="line250">250</a>       <font color="#444444">/* Set the ordering of the variables in the finite element problem.  This
<a name="line251">251</a>          is done by listing the variable offset directions relative to the
<a name="line252">252</a>          element's center.  See the Reference Manual for more details. */</font>
<a name="line253">253</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line254">254</a>          <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line255">255</a>          <strong>int</strong> <font color="#2040a0">ordering</font><font color="4444FF">[</font><font color="#FF0000">12</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font> <font color="#FF0000">0</font>, <font color="4444FF">-</font><font color="#FF0000">1</font>, <font color="4444FF">-</font><font color="#FF0000">1</font>,    <font color="#444444">/*    [3]------[2] */</font>
<a name="line256">256</a>                               <font color="#FF0000">0</font>, <font color="4444FF">+</font><font color="#FF0000">1</font>, <font color="4444FF">-</font><font color="#FF0000">1</font>,    <font color="#444444">/*    /        /   */</font>
<a name="line257">257</a>                               <font color="#FF0000">0</font>, <font color="4444FF">+</font><font color="#FF0000">1</font>, <font color="4444FF">+</font><font color="#FF0000">1</font>,    <font color="#444444">/*   /        /    */</font>
<a name="line258">258</a>                               <font color="#FF0000">0</font>, <font color="4444FF">-</font><font color="#FF0000">1</font>, <font color="4444FF">+</font><font color="#FF0000">1</font> <font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>  <font color="#444444">/* [0]------[1]    */</font>
<a name="line259">259</a> 
<a name="line260">260</a>          <font color="#2040a0">HYPRE_SStructGridSetFEMOrdering</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ordering</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line261">261</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line262">262</a> 
<a name="line263">263</a>       <font color="#444444">/* Now we need to set the spatial relation between each of the parts.
<a name="line264">264</a>          Since we are using nodal variables, we have to use SetSharedPart to
<a name="line265">265</a>          establish the connection at the origin. */</font>
<a name="line266">266</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line267">267</a>          <font color="#444444">/* Relation to the clockwise-previous neighbor part, e.g. 0 and 1 for
<a name="line268">268</a>             the case of 6 parts.  Note that we could have used SetNeighborPart
<a name="line269">269</a>             here instead of SetSharedPart. */</font>
<a name="line270">270</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line271">271</a>             <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line272">272</a>             <font color="#444444">/* the box of cells intersecting the boundary in the current part */</font>
<a name="line273">273</a>             <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#2040a0">n</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line274">274</a>             <font color="#444444">/* share all data on the left side of the box */</font>
<a name="line275">275</a>             <strong>int</strong> <font color="#2040a0">offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line276">276</a> 
<a name="line277">277</a>             <strong>int</strong> <font color="#2040a0">shared_part</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font> <font color="4444FF">%</font> <font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line278">278</a>             <font color="#444444">/* the box of cells intersecting the boundary in the neighbor */</font>
<a name="line279">279</a>             <strong>int</strong> <font color="#2040a0">shared_ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">shared_iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">n</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line280">280</a>             <font color="#444444">/* share all data on the bottom of the box */</font>
<a name="line281">281</a>             <strong>int</strong> <font color="#2040a0">shared_offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">0</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line282">282</a> 
<a name="line283">283</a>             <font color="#444444">/* x/y-direction on the current part is -y/x on the neighbor */</font>
<a name="line284">284</a>             <strong>int</strong> <font color="#2040a0">index_map</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line285">285</a>             <strong>int</strong> <font color="#2040a0">index_dir</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line286">286</a> 
<a name="line287">287</a>             <font color="#2040a0">HYPRE_SStructGridSetSharedPart</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">offset</font>,
<a name="line288">288</a>                                            <font color="#2040a0">shared_part</font>, <font color="#2040a0">shared_ilower</font>,
<a name="line289">289</a>                                            <font color="#2040a0">shared_iupper</font>, <font color="#2040a0">shared_offset</font>,
<a name="line290">290</a>                                            <font color="#2040a0">index_map</font>, <font color="#2040a0">index_dir</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line291">291</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line292">292</a> 
<a name="line293">293</a>          <font color="#444444">/* Relation to the clockwise-following neighbor part, e.g. 0 and 5 for
<a name="line294">294</a>             the case of 6 parts.  Note that we could have used SetNeighborPart
<a name="line295">295</a>             here instead of SetSharedPart. */</font>
<a name="line296">296</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line297">297</a>             <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line298">298</a>             <font color="#444444">/* the box of cells intersecting the boundary in the current part */</font>
<a name="line299">299</a>             <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">n</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line300">300</a>             <font color="#444444">/* share all data on the bottom of the box */</font>
<a name="line301">301</a>             <strong>int</strong> <font color="#2040a0">offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">0</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line302">302</a> 
<a name="line303">303</a>             <strong>int</strong> <font color="#2040a0">shared_part</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#2040a0">num_procs</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font> <font color="4444FF">%</font> <font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line304">304</a>             <font color="#444444">/* the box of cells intersecting the boundary in the neighbor */</font>
<a name="line305">305</a>             <strong>int</strong> <font color="#2040a0">shared_ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">shared_iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#2040a0">n</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line306">306</a>             <font color="#444444">/* share all data on the left side of the box */</font>
<a name="line307">307</a>             <strong>int</strong> <font color="#2040a0">shared_offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line308">308</a> 
<a name="line309">309</a>             <font color="#444444">/* x/y-direction on the current part is y/-x on the neighbor */</font>
<a name="line310">310</a>             <strong>int</strong> <font color="#2040a0">index_map</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line311">311</a>             <strong>int</strong> <font color="#2040a0">index_dir</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line312">312</a> 
<a name="line313">313</a>             <font color="#2040a0">HYPRE_SStructGridSetSharedPart</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">offset</font>,
<a name="line314">314</a>                                            <font color="#2040a0">shared_part</font>, <font color="#2040a0">shared_ilower</font>,
<a name="line315">315</a>                                            <font color="#2040a0">shared_iupper</font>, <font color="#2040a0">shared_offset</font>,
<a name="line316">316</a>                                            <font color="#2040a0">index_map</font>, <font color="#2040a0">index_dir</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line317">317</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line318">318</a> 
<a name="line319">319</a>          <font color="#444444">/* Relation to all other parts, e.g. 0 and 2,3,4.  This can be
<a name="line320">320</a>             described only by SetSharedPart. */</font>
<a name="line321">321</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line322">322</a>             <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line323">323</a>             <font color="#444444">/* the (one cell) box that touches the origin */</font>
<a name="line324">324</a>             <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line325">325</a>             <font color="#444444">/* share all data in the bottom left corner (i.e. the origin) */</font>
<a name="line326">326</a>             <strong>int</strong> <font color="#2040a0">offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line327">327</a> 
<a name="line328">328</a>             <strong>int</strong> <font color="#2040a0">shared_part</font><font color="4444FF">;</font>
<a name="line329">329</a>             <font color="#444444">/* the box of one cell that touches the origin */</font>
<a name="line330">330</a>             <strong>int</strong> <font color="#2040a0">shared_ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font>, <font color="#2040a0">shared_iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">1</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line331">331</a>             <font color="#444444">/* share all data in the bottom left corner (i.e. the origin) */</font>
<a name="line332">332</a>             <strong>int</strong> <font color="#2040a0">shared_offset</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line333">333</a> 
<a name="line334">334</a>             <font color="#444444">/* x/y-direction on the current part is -x/-y on the neighbor, but
<a name="line335">335</a>                in this case the arguments are not really important since we are
<a name="line336">336</a>                only sharing a point */</font>
<a name="line337">337</a>             <strong>int</strong> <font color="#2040a0">index_map</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">0</font>,<font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line338">338</a>             <strong>int</strong> <font color="#2040a0">index_dir</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line339">339</a> 
<a name="line340">340</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">shared_part</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">shared_part</font> <font color="4444FF">&lt;</font> <font color="#2040a0">myid</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">shared_part</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line341">341</a>                <font color="#2040a0">HYPRE_SStructGridSetSharedPart</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">offset</font>,
<a name="line342">342</a>                                               <font color="#2040a0">shared_part</font>, <font color="#2040a0">shared_ilower</font>,
<a name="line343">343</a>                                               <font color="#2040a0">shared_iupper</font>, <font color="#2040a0">shared_offset</font>,
<a name="line344">344</a>                                               <font color="#2040a0">index_map</font>, <font color="#2040a0">index_dir</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line345">345</a> 
<a name="line346">346</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">shared_part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">2</font><font color="4444FF">;</font> <font color="#2040a0">shared_part</font> <font color="4444FF">&lt;</font> <font color="#2040a0">num_procs</font><font color="4444FF">;</font> <font color="#2040a0">shared_part</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line347">347</a>                <font color="#2040a0">HYPRE_SStructGridSetSharedPart</font><font color="4444FF">(</font><font color="#2040a0">grid</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">offset</font>,
<a name="line348">348</a>                                               <font color="#2040a0">shared_part</font>, <font color="#2040a0">shared_ilower</font>,
<a name="line349">349</a>                                               <font color="#2040a0">shared_iupper</font>, <font color="#2040a0">shared_offset</font>,
<a name="line350">350</a>                                               <font color="#2040a0">index_map</font>, <font color="#2040a0">index_dir</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line351">351</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line352">352</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line353">353</a> 
<a name="line354">354</a>       <font color="#444444">/* Now the grid is ready to be used */</font>
<a name="line355">355</a>       <font color="#2040a0">HYPRE_SStructGridAssemble</font><font color="4444FF">(</font><font color="#2040a0">grid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line356">356</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line357">357</a> 
<a name="line358">358</a>    <font color="#444444">/* 2. Set up the Graph - this determines the non-zero structure of the
<a name="line359">359</a>          matrix. */</font>
<a name="line360">360</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line361">361</a>       <strong>int</strong> <font color="#2040a0">part</font><font color="4444FF">;</font>
<a name="line362">362</a> 
<a name="line363">363</a>       <font color="#444444">/* Create the graph object */</font>
<a name="line364">364</a>       <font color="#2040a0">HYPRE_SStructGraphCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">grid</font>, <font color="4444FF">&amp;</font><font color="#2040a0">graph</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line365">365</a> 
<a name="line366">366</a>       <font color="#444444">/* See MatrixSetObjectType below */</font>
<a name="line367">367</a>       <font color="#2040a0">HYPRE_SStructGraphSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">graph</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line368">368</a> 
<a name="line369">369</a>       <font color="#444444">/* Indicate that this problem uses finite element stiffness matrices and
<a name="line370">370</a>          load vectors, instead of stencils. */</font>
<a name="line371">371</a>       <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">part</font> <font color="4444FF">&lt;</font> <font color="#2040a0">num_procs</font><font color="4444FF">;</font> <font color="#2040a0">part</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line372">372</a>          <font color="#2040a0">HYPRE_SStructGraphSetFEM</font><font color="4444FF">(</font><font color="#2040a0">graph</font>, <font color="#2040a0">part</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line373">373</a> 
<a name="line374">374</a>       <font color="#444444">/* The local stiffness matrix is full, so there is no need to call
<a name="line375">375</a>          HYPRE_SStructGraphSetFEMSparsity to set its sparsity pattern. */</font>
<a name="line376">376</a> 
<a name="line377">377</a>       <font color="#444444">/* Assemble the graph */</font>
<a name="line378">378</a>       <font color="#2040a0">HYPRE_SStructGraphAssemble</font><font color="4444FF">(</font><font color="#2040a0">graph</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line379">379</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line380">380</a> 
<a name="line381">381</a>    <font color="#444444">/* 3. Set up the SStruct Matrix and right-hand side vector */</font>
<a name="line382">382</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line383">383</a>       <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line384">384</a> 
<a name="line385">385</a>       <font color="#444444">/* Create the matrix object */</font>
<a name="line386">386</a>       <font color="#2040a0">HYPRE_SStructMatrixCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">graph</font>, <font color="4444FF">&amp;</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line387">387</a>       <font color="#444444">/* Use a ParCSR storage */</font>
<a name="line388">388</a>       <font color="#2040a0">HYPRE_SStructMatrixSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line389">389</a>       <font color="#444444">/* Indicate that the matrix coefficients are ready to be set */</font>
<a name="line390">390</a>       <font color="#2040a0">HYPRE_SStructMatrixInitialize</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line391">391</a> 
<a name="line392">392</a>       <font color="#444444">/* Create an empty vector object */</font>
<a name="line393">393</a>       <font color="#2040a0">HYPRE_SStructVectorCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">grid</font>, <font color="4444FF">&amp;</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line394">394</a>       <font color="#444444">/* Use a ParCSR storage */</font>
<a name="line395">395</a>       <font color="#2040a0">HYPRE_SStructVectorSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line396">396</a>       <font color="#444444">/* Indicate that the vector coefficients are ready to be set */</font>
<a name="line397">397</a>       <font color="#2040a0">HYPRE_SStructVectorInitialize</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line398">398</a> 
<a name="line399">399</a>       <font color="#444444">/* Set the matrix and vector entries by finite element assembly */</font>
<a name="line400">400</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line401">401</a>          <font color="#444444">/* local stifness matrix and load vector */</font>
<a name="line402">402</a>          <strong>double</strong> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font>, <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">4</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line403">403</a> 
<a name="line404">404</a>          <strong>int</strong> <font color="#2040a0">i</font>, <font color="#2040a0">j</font>, <font color="#2040a0">k</font><font color="4444FF">;</font>
<a name="line405">405</a>          <strong>int</strong> <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line406">406</a> 
<a name="line407">407</a>          <font color="#444444">/* set the values in the interior cells */</font>
<a name="line408">408</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line409">409</a>             <font color="#2040a0">ComputeFEMRhombus</font><font color="4444FF">(</font><font color="#2040a0">S</font>, <font color="#2040a0">F</font>, <font color="#2040a0">gamma</font>, <font color="#2040a0">h</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line410">410</a> 
<a name="line411">411</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line412">412</a>                <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">j</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line413">413</a>                <font color="4444FF"><strong>{</strong></font>
<a name="line414">414</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line415">415</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">j</font><font color="4444FF">;</font>
<a name="line416">416</a>                   <font color="#2040a0">HYPRE_SStructMatrixAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="4444FF">&amp;</font><font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line417">417</a>                   <font color="#2040a0">HYPRE_SStructVectorAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="#2040a0">F</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line418">418</a>                <font color="4444FF"><strong>}</strong></font>
<a name="line419">419</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line420">420</a> 
<a name="line421">421</a>          <font color="#444444">/* cells having nodes 1,2 on the domain boundary */</font>
<a name="line422">422</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line423">423</a>             <font color="#2040a0">ComputeFEMRhombus</font><font color="4444FF">(</font><font color="#2040a0">S</font>, <font color="#2040a0">F</font>, <font color="#2040a0">gamma</font>, <font color="#2040a0">h</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line424">424</a> 
<a name="line425">425</a>             <font color="#444444">/* eliminate nodes 1,2 from S and F */</font>
<a name="line426">426</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">k</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">k</font> <font color="4444FF">&lt;</font> <font color="#FF0000">4</font><font color="4444FF">;</font> <font color="#2040a0">k</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line427">427</a>             <font color="4444FF"><strong>{</strong></font>
<a name="line428">428</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line429">429</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line430">430</a>             <font color="4444FF"><strong>}</strong></font>
<a name="line431">431</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line432">432</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line433">433</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line434">434</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line435">435</a> 
<a name="line436">436</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line437">437</a>                <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">j</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line438">438</a>                <font color="4444FF"><strong>{</strong></font>
<a name="line439">439</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line440">440</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">j</font><font color="4444FF">;</font>
<a name="line441">441</a>                   <font color="#2040a0">HYPRE_SStructMatrixAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="4444FF">&amp;</font><font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line442">442</a>                   <font color="#2040a0">HYPRE_SStructVectorAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="#2040a0">F</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line443">443</a>                <font color="4444FF"><strong>}</strong></font>
<a name="line444">444</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line445">445</a> 
<a name="line446">446</a>          <font color="#444444">/* cells having nodes 2,3 on the domain boundary */</font>
<a name="line447">447</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line448">448</a>             <font color="#2040a0">ComputeFEMRhombus</font><font color="4444FF">(</font><font color="#2040a0">S</font>, <font color="#2040a0">F</font>, <font color="#2040a0">gamma</font>, <font color="#2040a0">h</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line449">449</a> 
<a name="line450">450</a>             <font color="#444444">/* eliminate nodes 2,3 from S and F */</font>
<a name="line451">451</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">k</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">k</font> <font color="4444FF">&lt;</font> <font color="#FF0000">4</font><font color="4444FF">;</font> <font color="#2040a0">k</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line452">452</a>             <font color="4444FF"><strong>{</strong></font>
<a name="line453">453</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line454">454</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line455">455</a>             <font color="4444FF"><strong>}</strong></font>
<a name="line456">456</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line457">457</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line458">458</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line459">459</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line460">460</a> 
<a name="line461">461</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line462">462</a>                <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line463">463</a>                <font color="4444FF"><strong>{</strong></font>
<a name="line464">464</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line465">465</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">j</font><font color="4444FF">;</font>
<a name="line466">466</a>                   <font color="#2040a0">HYPRE_SStructMatrixAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="4444FF">&amp;</font><font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line467">467</a>                   <font color="#2040a0">HYPRE_SStructVectorAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="#2040a0">F</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line468">468</a>                <font color="4444FF"><strong>}</strong></font>
<a name="line469">469</a> 
<a name="line470">470</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line471">471</a> 
<a name="line472">472</a>          <font color="#444444">/* cells having nodes 1,2,3 on the domain boundary */</font>
<a name="line473">473</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line474">474</a>             <font color="#2040a0">ComputeFEMRhombus</font><font color="4444FF">(</font><font color="#2040a0">S</font>, <font color="#2040a0">F</font>, <font color="#2040a0">gamma</font>, <font color="#2040a0">h</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line475">475</a> 
<a name="line476">476</a>             <font color="#444444">/* eliminate nodes 2,3 from S and F */</font>
<a name="line477">477</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">k</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">k</font> <font color="4444FF">&lt;</font> <font color="#FF0000">4</font><font color="4444FF">;</font> <font color="#2040a0">k</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line478">478</a>             <font color="4444FF"><strong>{</strong></font>
<a name="line479">479</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line480">480</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line481">481</a>                <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#2040a0">k</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line482">482</a>             <font color="4444FF"><strong>}</strong></font>
<a name="line483">483</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line484">484</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line485">485</a>             <font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line486">486</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line487">487</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line488">488</a>             <font color="#2040a0">F</font><font color="4444FF">[</font><font color="#FF0000">3</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font><font color="4444FF">;</font>
<a name="line489">489</a> 
<a name="line490">490</a>             <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line491">491</a>                <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#2040a0">j</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line492">492</a>                <font color="4444FF"><strong>{</strong></font>
<a name="line493">493</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line494">494</a>                   <font color="#2040a0">index</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">j</font><font color="4444FF">;</font>
<a name="line495">495</a>                   <font color="#2040a0">HYPRE_SStructMatrixAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="4444FF">&amp;</font><font color="#2040a0">S</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line496">496</a>                   <font color="#2040a0">HYPRE_SStructVectorAddFEMValues</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">part</font>, <font color="#2040a0">index</font>, <font color="#2040a0">F</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line497">497</a>                <font color="4444FF"><strong>}</strong></font>
<a name="line498">498</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line499">499</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line500">500</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line501">501</a> 
<a name="line502">502</a>    <font color="#444444">/* Collective calls finalizing the matrix and vector assembly */</font>
<a name="line503">503</a>    <font color="#2040a0">HYPRE_SStructMatrixAssemble</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line504">504</a>    <font color="#2040a0">HYPRE_SStructVectorAssemble</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line505">505</a> 
<a name="line506">506</a>    <font color="#444444">/* 4. Set up SStruct Vector for the solution vector x */</font>
<a name="line507">507</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line508">508</a>       <strong>int</strong> <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line509">509</a>       <strong>int</strong> <font color="#2040a0">var</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line510">510</a>       <strong>int</strong> <font color="#2040a0">nvalues</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">*</font><font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line511">511</a>       <strong>double</strong> <font color="4444FF">*</font><font color="#2040a0">values</font><font color="4444FF">;</font>
<a name="line512">512</a> 
<a name="line513">513</a>       <font color="#444444">/* Since the SetBoxValues() calls below set the values of the nodes in
<a name="line514">514</a>          the upper-right corners of the cells, the nodal box should start
<a name="line515">515</a>          from (0,0) instead of (1,1). */</font>
<a name="line516">516</a>       <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">0</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line517">517</a>       <strong>int</strong> <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">n</font>,<font color="#2040a0">n</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line518">518</a> 
<a name="line519">519</a>       <font color="#2040a0">values</font> <font color="4444FF">=</font> <font color="#2040a0">calloc</font><font color="4444FF">(</font><font color="#2040a0">nvalues</font>, <strong>sizeof</strong><font color="4444FF">(</font><strong>double</strong><font color="4444FF">)</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line520">520</a> 
<a name="line521">521</a>       <font color="#444444">/* Create an empty vector object */</font>
<a name="line522">522</a>       <font color="#2040a0">HYPRE_SStructVectorCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">grid</font>, <font color="4444FF">&amp;</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line523">523</a>       <font color="#444444">/* Set the object type to ParCSR */</font>
<a name="line524">524</a>       <font color="#2040a0">HYPRE_SStructVectorSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line525">525</a>       <font color="#444444">/* Indicate that the vector coefficients are ready to be set */</font>
<a name="line526">526</a>       <font color="#2040a0">HYPRE_SStructVectorInitialize</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line527">527</a>       <font color="#444444">/* Set the values for the initial guess */</font>
<a name="line528">528</a>       <font color="#2040a0">HYPRE_SStructVectorSetBoxValues</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">var</font>, <font color="#2040a0">values</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line529">529</a> 
<a name="line530">530</a>       <font color="#2040a0">free</font><font color="4444FF">(</font><font color="#2040a0">values</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line531">531</a> 
<a name="line532">532</a>       <font color="#444444">/* Finalize the vector assembly */</font>
<a name="line533">533</a>       <font color="#2040a0">HYPRE_SStructVectorAssemble</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line534">534</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line535">535</a> 
<a name="line536">536</a>    <font color="#444444">/* 5. Set up and call the solver (Solver options can be found in the
<a name="line537">537</a>          Reference Manual.) */</font>
<a name="line538">538</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line539">539</a>       <strong>double</strong> <font color="#2040a0">final_res_norm</font><font color="4444FF">;</font>
<a name="line540">540</a>       <strong>int</strong> <font color="#2040a0">its</font><font color="4444FF">;</font>
<a name="line541">541</a> 
<a name="line542">542</a>       <font color="#2040a0">HYPRE_ParCSRMatrix</font>    <font color="#2040a0">par_A</font><font color="4444FF">;</font>
<a name="line543">543</a>       <font color="#2040a0">HYPRE_ParVector</font>       <font color="#2040a0">par_b</font><font color="4444FF">;</font>
<a name="line544">544</a>       <font color="#2040a0">HYPRE_ParVector</font>       <font color="#2040a0">par_x</font><font color="4444FF">;</font>
<a name="line545">545</a> 
<a name="line546">546</a>       <font color="#444444">/* Extract the ParCSR objects needed in the solver */</font>
<a name="line547">547</a>       <font color="#2040a0">HYPRE_SStructMatrixGetObject</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">par_A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line548">548</a>       <font color="#2040a0">HYPRE_SStructVectorGetObject</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">par_b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line549">549</a>       <font color="#2040a0">HYPRE_SStructVectorGetObject</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line550">550</a> 
<a name="line551">551</a>       <font color="#444444">/* Here we construct a BoomerAMG solver.  See the other SStruct examples
<a name="line552">552</a>          as well as the Reference manual for additional solver choices. */</font>
<a name="line553">553</a>       <font color="#2040a0">HYPRE_BoomerAMGCreate</font><font color="4444FF">(</font><font color="4444FF">&amp;</font><font color="#2040a0">solver</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line554">554</a>       <font color="#2040a0">HYPRE_BoomerAMGSetCoarsenType</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#FF0000">6</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line555">555</a>       <font color="#2040a0">HYPRE_BoomerAMGSetStrongThreshold</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#FF0000">0.25</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line556">556</a>       <font color="#2040a0">HYPRE_BoomerAMGSetTol</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#FF0000">1e-6</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line557">557</a>       <font color="#2040a0">HYPRE_BoomerAMGSetPrintLevel</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#FF0000">2</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line558">558</a>       <font color="#2040a0">HYPRE_BoomerAMGSetMaxIter</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#FF0000">50</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line559">559</a> 
<a name="line560">560</a>       <font color="#444444">/* call the setup */</font>
<a name="line561">561</a>       <font color="#2040a0">HYPRE_BoomerAMGSetup</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#2040a0">par_A</font>, <font color="#2040a0">par_b</font>, <font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line562">562</a> 
<a name="line563">563</a>       <font color="#444444">/* call the solve */</font>
<a name="line564">564</a>       <font color="#2040a0">HYPRE_BoomerAMGSolve</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="#2040a0">par_A</font>, <font color="#2040a0">par_b</font>, <font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line565">565</a> 
<a name="line566">566</a>       <font color="#444444">/* get some info */</font>
<a name="line567">567</a>       <font color="#2040a0">HYPRE_BoomerAMGGetNumIterations</font><font color="4444FF">(</font><font color="#2040a0">solver</font>, <font color="4444FF">&amp;</font><font color="#2040a0">its</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line568">568</a>       <font color="#2040a0">HYPRE_BoomerAMGGetFinalRelativeResidualNorm</font><font color="4444FF">(</font><font color="#2040a0">solver</font>,
<a name="line569">569</a>                                                   <font color="4444FF">&amp;</font><font color="#2040a0">final_res_norm</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line570">570</a>       <font color="#444444">/* clean up */</font>
<a name="line571">571</a>       <font color="#2040a0">HYPRE_BoomerAMGDestroy</font><font color="4444FF">(</font><font color="#2040a0">solver</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line572">572</a> 
<a name="line573">573</a>       <font color="#444444">/* Gather the solution vector */</font>
<a name="line574">574</a>       <font color="#2040a0">HYPRE_SStructVectorGather</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line575">575</a> 
<a name="line576">576</a>       <font color="#444444">/* Save the solution for GLVis visualization, see vis/glvis-ex13.sh */</font>
<a name="line577">577</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">vis</font><font color="4444FF">)</font>
<a name="line578">578</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line579">579</a>          <font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">file</font><font color="4444FF">;</font>
<a name="line580">580</a>          <strong>char</strong> <font color="#2040a0">filename</font><font color="4444FF">[</font><font color="#FF0000">255</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line581">581</a> 
<a name="line582">582</a>          <strong>int</strong> <font color="#2040a0">i</font>, <font color="#2040a0">part</font> <font color="4444FF">=</font> <font color="#2040a0">myid</font>, <font color="#2040a0">var</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line583">583</a>          <strong>int</strong> <font color="#2040a0">nvalues</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">*</font><font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line584">584</a>          <strong>double</strong> <font color="4444FF">*</font><font color="#2040a0">values</font> <font color="4444FF">=</font> <font color="#2040a0">calloc</font><font color="4444FF">(</font><font color="#2040a0">nvalues</font>, <strong>sizeof</strong><font color="4444FF">(</font><strong>double</strong><font color="4444FF">)</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line585">585</a>          <strong>int</strong> <font color="#2040a0">ilower</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#FF0000">0</font>,<font color="#FF0000">0</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line586">586</a>          <strong>int</strong> <font color="#2040a0">iupper</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font><font color="#2040a0">n</font>,<font color="#2040a0">n</font><font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>
<a name="line587">587</a> 
<a name="line588">588</a>          <font color="#444444">/* get all local data (including a local copy of the shared values) */</font>
<a name="line589">589</a>          <font color="#2040a0">HYPRE_SStructVectorGetBoxValues</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="#2040a0">part</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>,
<a name="line590">590</a>                                          <font color="#2040a0">var</font>, <font color="#2040a0">values</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line591">591</a> 
<a name="line592">592</a>          <font color="#2040a0">sprintf</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;%s.%06d&quot;</font>, <font color="#008000">&quot;vis/ex14.sol&quot;</font>, <font color="#2040a0">myid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line593">593</a>          <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">file</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;w&quot;</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font>
<a name="line594">594</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line595">595</a>             <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Error: can't open output file %s<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">filename</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line596">596</a>             <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line597">597</a>             <font color="#2040a0">exit</font><font color="4444FF">(</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line598">598</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line599">599</a> 
<a name="line600">600</a>          <font color="#444444">/* finite element space header */</font>
<a name="line601">601</a>          <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;FiniteElementSpace<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line602">602</a>          <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;FiniteElementCollection: H1_2D_P1<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line603">603</a>          <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;VDim: 1<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line604">604</a>          <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;Ordering: 0<font color="#77dd77">\n</font><font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line605">605</a> 
<a name="line606">606</a>          <font color="#444444">/* save solution */</font>
<a name="line607">607</a>          <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font> <font color="#2040a0">nvalues</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line608">608</a>             <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;%.14e<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line609">609</a> 
<a name="line610">610</a>          <font color="#2040a0">fflush</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line611">611</a>          <font color="#2040a0">fclose</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line612">612</a>          <font color="#2040a0">free</font><font color="4444FF">(</font><font color="#2040a0">values</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line613">613</a> 
<a name="line614">614</a>          <font color="#444444">/* save local finite element mesh */</font>
<a name="line615">615</a>          <font color="#2040a0">GLVis_PrintLocalRhombusMesh</font><font color="4444FF">(</font><font color="#008000">&quot;vis/ex14.mesh&quot;</font>, <font color="#2040a0">n</font>, <font color="#2040a0">myid</font>, <font color="#2040a0">gamma</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line616">616</a> 
<a name="line617">617</a>          <font color="#444444">/* additional visualization data */</font>
<a name="line618">618</a>          <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font>
<a name="line619">619</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line620">620</a>             <font color="#2040a0">sprintf</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;%s&quot;</font>, <font color="#008000">&quot;vis/ex14.data&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line621">621</a>             <font color="#2040a0">file</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;w&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line622">622</a>             <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;np %d<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">num_procs</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line623">623</a>             <font color="#2040a0">fflush</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line624">624</a>             <font color="#2040a0">fclose</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line625">625</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line626">626</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line627">627</a> 
<a name="line628">628</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font>
<a name="line629">629</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line630">630</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line631">631</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Iterations = %d<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">its</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line632">632</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Final Relative Residual Norm = %g<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">final_res_norm</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line633">633</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line634">634</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line635">635</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line636">636</a> 
<a name="line637">637</a>    <font color="#444444">/* Free memory */</font>
<a name="line638">638</a>    <font color="#2040a0">HYPRE_SStructGridDestroy</font><font color="4444FF">(</font><font color="#2040a0">grid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line639">639</a>    <font color="#2040a0">HYPRE_SStructGraphDestroy</font><font color="4444FF">(</font><font color="#2040a0">graph</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line640">640</a>    <font color="#2040a0">HYPRE_SStructMatrixDestroy</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line641">641</a>    <font color="#2040a0">HYPRE_SStructVectorDestroy</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line642">642</a>    <font color="#2040a0">HYPRE_SStructVectorDestroy</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line643">643</a> 
<a name="line644">644</a>    <font color="#444444">/* Finalize MPI */</font>
<a name="line645">645</a>    <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line646">646</a> 
<a name="line647">647</a>    <strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line648">648</a> <font color="4444FF"><strong>}</strong></font>

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
